<template>
    <el-row>
        <el-col :span="8" :gutter="20">
            <el-card shadow="hover">
                <div class="card">
                    <div class="c-f">
                        <img src="../assets/cool.jpg" class="i" alt="">
                        <div style="margin-left: 20px;">
                            <div style="margin-bottom: 10px;font-size: 40px;">Admin</div>
                            <div>超级管理员</div>
                        </div>
                    </div>
                    <div>
                        <div class="f">
                            <p>上次登录时间:</p>
                            <p style="margin-left: 20px;">2025-5-17</p>
                        </div>
                        <div class="f">
                            <p>上次登录地点:</p>
                            <p style="margin-left: 20px;">江门</p>
                        </div>
                    </div>
                </div>
            </el-card>

            <el-card shadow="hover" style="margin-top: 30px;">
                <div>
                    <el-table :data="data.tableData" style="width: 100%">
                        <el-table-column prop="name" label="手机型号" />
                        <el-table-column prop="todayBuy" label="今日购买" />
                        <el-table-column prop="monthBuy" label="本月购买" />
                        <el-table-column prop="total" label="总购买" />
                    </el-table>
                </div>
            </el-card>

        </el-col>
        <el-col :span="16">
            <div class="num">
                <el-card shadow="hover" :body-style="{ display: 'flex', padding: 0 }"
                    v-for="(item, index) in data.countData" :key="index">
                    <component :is="item.icon" class="icon" :style="{ background: item.color }"> </component>
                    <div class="detail">
                        <p class="num">￥{{ item.value }}</p>
                        <p class="tet">{{ item.name }} </p>
                    </div>
                </el-card>
            </div>

            <!-- 按钮权限控制-v-permission="'home:add'" -->
            <div class="ech" v-permission="'home:add'">
                <echar-one></echar-one>
            </div>

            <div class="bt">
                <div class="second">
                    <echar-second></echar-second>
                </div>
                <div class="third">
                    <echar-third></echar-third>
                </div>
            </div>

        </el-col>
    </el-row>

</template>

<script setup>
import { ref, reactive, getCurrentInstance, onMounted } from 'vue'
import echarOne from '@/components/echarOne.vue'
import echarSecond from '@/components/echarSecond.vue'
import echarThird from '@/components/echarThird.vue'
const { proxy } = getCurrentInstance()
let data = reactive({
    tableData: [],
    countData: [],
    charData: []
})


onMounted(() => {
    getHomeData()
    getCountData()
})
let getHomeData = async () => {
    let res = await proxy.$api.getTableData()
    data.tableData = res.tableData
    console.log('getTableDatas', res);
}
let getCountData = async () => {
    let res = await proxy.$api.getCountData()
    console.log('getCountData', res);
    data.countData = res
}
</script>

<style lang='less' scoped>
.card {
    padding: 10px;

    .c-f {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-bottom: 20px;
        border-bottom: 1px solid #f2f2f2;

        .i {
            width: 150px;
            height: 150px;
            border-radius: 50%;
        }
    }

    .f {
        display: flex;
        justify-content: flex-start;
    }
}

.num {
    display: flex;
    flex-wrap: wrap;
    margin-left: 20px;

    .el-card {
        width: 30%;
        height: 60px;
        margin-bottom: 20px;
        margin-right: 20px;

        .icon {
            width: 60px;
            height: 60px;
        }

        .detail {
            margin-left: 20px;
            height: 60px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;

            .num {
                margin-left: 0px;
                font-size: 17px;
                font-weight: bold;
            }

        }
    }
}

.ech {
    padding: 0px 20px 10px;
}

.bt {
    display: flex;
    justify-content: space-between;

    .second {
        margin-left: 20px;
        width: 48%;
    }

    .third {
        width: 48%;
        margin-right: 20px;
    }
}
</style>